package wang.z.JFrame;

import wang.z.component.*;
import wang.z.utils.PathUtils;
import wang.z.utils.ScreenUtils;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Vector;

/**
 * @author like
 * @date 2022/12/11 16:00
 * @Description TODO
 */
public class Manager {
    JFrame jf = new JFrame("管理员界面");

    final int WIDTH = 600;
    final int HEIGHT = 400;

    public void init() throws IOException {

        jf.setBounds((ScreenUtils.getScreenWidth() - WIDTH) / 2, (ScreenUtils.getScreenHeight() - HEIGHT) / 2-200, WIDTH, HEIGHT);
        jf.setResizable(false);
        jf.setIconImage(ImageIO.read(new File(PathUtils.getRealPath("logo.png"))));

        //设置菜单栏
        JMenuBar jmb = new JMenuBar();
        JMenu jMenu1 = new JMenu("类别管理");
        JMenu jMenu2 = new JMenu("书籍管理");
        JMenu jMenu3 = new JMenu("用户管理");
        JMenu jMenu4 = new JMenu("退出系统");
        jMenu1.setFont(new Font("幼圆",Font.BOLD, 16));
        jMenu2.setFont(new Font("幼圆",Font.BOLD, 16));
        jMenu3.setFont(new Font("幼圆",Font.BOLD, 16));
        jMenu4.setFont(new Font("幼圆",Font.BOLD, 16));

        JMenuItem type_m1 = new JMenuItem("类别管理");
        JMenuItem book_m1 = new JMenuItem("添加");
        JMenuItem userB_m = new JMenuItem("借阅详情");
        JMenuItem book_m2 = new JMenuItem("修改");//书籍
        JMenuItem user_m = new JMenuItem("修改");//用户信息
        JMenuItem typeU_m1 = new JMenuItem("修改");//类别信息
        JMenuItem m6 = new JMenuItem("切换用户");//类别信息
        JMenuItem m7 = new JMenuItem("直接退出");//类别信息
        type_m1.setFont(new Font("幼圆",Font.BOLD, 16));
        book_m1.setFont(new Font("幼圆",Font.BOLD, 16));
        book_m2.setFont(new Font("幼圆",Font.BOLD, 16));
        user_m.setFont(new Font("幼圆",Font.BOLD, 16));
        typeU_m1.setFont(new Font("幼圆",Font.BOLD, 16));
        m6.setFont(new Font("幼圆",Font.BOLD, 16));
        m7.setFont(new Font("幼圆",Font.BOLD, 16));
        userB_m.setFont(new Font("幼圆",Font.BOLD, 16));

        book_m1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    for(Component co:jf.getRootPane().getContentPane().getComponents()) {
                        jf.remove(co);
                    }
                    new AdminBookAdd(jf);
                    jf.add(new BackGroundPanel(ImageIO.read(new File(PathUtils.getRealPath("library.jpg")))));

                    jf.setSize(600,400);
                    jf.repaint();


                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });

        book_m2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {

                    for(Component co:jf.getRootPane().getContentPane().getComponents()) {
                        jf.remove(co);
                    }
                    new AdminBookUpdate(jf);
                    jf.add(new BackGroundPanel(ImageIO.read(new File(PathUtils.getRealPath("library.jpg")))));

                    jf.setSize(600,600);
                    jf.repaint();


                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        user_m.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {

                    for(Component co:jf.getRootPane().getContentPane().getComponents()) {
                        jf.remove(co);
                    }
                    new UserUpdate(jf);
                    jf.add(new BackGroundPanel(ImageIO.read(new File(PathUtils.getRealPath("library.jpg")))));

                    jf.setSize(600,600);
                    jf.repaint();


                } catch (Exception ex) {
                    ex.printStackTrace();
            }
            }
        });
        userB_m.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {

                    for(Component co:jf.getRootPane().getContentPane().getComponents()) {
                        jf.remove(co);
                    }
                    new AdminBorrowInfo(jf);
                    jf.add(new BackGroundPanel(ImageIO.read(new File(PathUtils.getRealPath("library.jpg")))));

                    jf.setSize(600,400);
                    jf.repaint();


                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        type_m1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {

                    for(Component co:jf.getRootPane().getContentPane().getComponents()) {
                        jf.remove(co);
                    }
                    new BookTypeAdd(jf);
                    jf.add(new BackGroundPanel(ImageIO.read(new File(PathUtils.getRealPath("library.jpg")))));

                    jf.setSize(600,500);



                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        m7.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        typeU_m1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {

                    for(Component co:jf.getRootPane().getContentPane().getComponents()) {
                        jf.remove(co);
                    }
                    new BookTypeUpdate(jf);
                    jf.add(new BackGroundPanel(ImageIO.read(new File(PathUtils.getRealPath("library.jpg")))));

                    jf.setSize(600,600);
                    jf.repaint();


                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        m6.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                jf.dispose();
                try {
                    new loginFrm().init();
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
        jMenu1.add(type_m1);
        jMenu1.add(typeU_m1);
        jMenu2.add(book_m1);
        jMenu2.add(book_m2);
        jMenu3.add(user_m);
        jMenu3.add(userB_m);
        jMenu4.add(m6);
        jMenu4.add(m7);
        jmb.add(jMenu1);
        jmb.add(jMenu2);
        jmb.add(jMenu3);
        jmb.add(jMenu4);
        jf.add(new AdminBookAdd(jf));
        jf.add(new BackGroundPanel(ImageIO.read(new File(PathUtils.getRealPath("library.jpg")))));
        jf.add(new JPanel());
        jf.setJMenuBar(jmb);
        jf.setVisible(true);

    }


}
